package com.lyf.shop.services.Impl;

import com.lyf.shop.dao.Impl.ProductDaoImpl;
import com.lyf.shop.dao.ProductDao;
import com.lyf.shop.entity.Page;
import com.lyf.shop.entity.Product;
import com.lyf.shop.entity.Type;
import com.lyf.shop.services.ProductService;

import java.sql.SQLException;
import java.util.List;

public class ProductServiceImpl implements ProductService {
    private ProductDao pd = new ProductDaoImpl();
    @Override
    public int getCountByTid(int tid) {
        try {
            if(tid>0){
               return pd.getCountByTid(tid).intValue();
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return 0;
    }

    @Override
    public List<Product> getProListByTid(int tid, Page page) {
        try {
            if (tid>0){
                return pd.getProListByTid(tid,page);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return null;
    }

    @Override
    public Product getProById(int pid) {
        try {
            if (pid>0) {
                return pd.getProById(pid);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return null;
    }

    @Override
    public List<Product> getProListByKey(String pname, String ptime) {
        try {
            return pd.getProListByKey(pname,ptime);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return null;
    }



    @Override
    public int addPro(Product product) {
        if (product!=null){
            try {
                return pd.addPro(product);
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        }
        return 0;
    }
}
